<?php
require_once 'modules/content/models/Content.php';
require_once 'modules/book/models/Book.php';
require_once 'modules/language/models/Lang.php';
class contact_IndexController extends Nine_Controller_Action
{
	public function indexAction()
	{
        echo "contact";
		$objContent = new Models_Content();
		/**
		 * Display tempalte
		 */
	    
	    $contact = $objContent->getContentById(3)->toArray();
	    
	    $this->view->contact = $contact;
        $this->view->headTitle($contact['title']);
	    $this->view->menuId = array('contact', '');
	}
	public function aboutAction()
	{
		$objContent = new Models_Content();
		/**
		 * Display tempalte
		 */
		 
		$content = $objContent->getContentById(25);
		$content2 = $objContent->getContentById(27);
// 		 echo "<pre>";print_r($content);die;
		$this->view->content = $content;
		$this->view->content2 = $content2;
		$this->view->headTitle($content['title']);
		$this->view->menuId = array('about', '');
	}
	public function worksAction()
	{
		$objBook = new Models_Book();
        $objLang = new Models_Lang();
        $config = Nine_Registry::getConfig();
	    $allBook = $objBook->setAllLanguages(true)->getAllBooks(null, array('book_gid DESC', 'book_id ASC'));

//          echo "<pre>";print_r($allBook);die;

        $tmp = array();
        $tmp2 = false;
//         $tmpGid =
        if($allBook)
        {
        	$tmpGid = $allBook[0]['book_gid'];
        	foreach ($allBook as $index => $book) {
        	
        		/**
        		 * Change date
        		 */
        		if (0 != $book['created_date']) {
        			$book['created_date'] = date($config['dateFormat'], $book['created_date']);
        		} else {
        			$book['created_date'] = '';
        		}
        		if ($tmpGid != $book['book_gid']) {
        			$tmp[] = $tmp2;
        			$tmp2 = false;
        			$tmpGid = $book['book_gid'];
        		}
        		if (false === $tmp2) {
        			$tmp2 = $book;
        		}
        	
        		$tmp2['langs'][] = $book;
        	
        		if ($index == count($allBook) - 1) {
        			$tmp[] = $tmp2;
        		}
        	}
        	$allBook = $tmp;
        }
		$this->view->books = $allBook;
// 		echo "<pre>";print_r($allBook);die;
		
		$this->view->headTitle('Works');
		$this->view->menuId = array('works', '');
	}
	public function joinAction()
	{
		$objContent = new Models_Content();
		/**
		 * Display tempalte
		 */
			
		$content = $objContent->getContentById(23);
		$content2 = $objContent->getContentById(29);
		// 		 echo "<pre>";print_r($content);die;
		$this->view->content2 = $content2;
		$this->view->content = $content;
		$this->view->headTitle($content['title']);
		$this->view->menuId = array('join', '');
	}
	public function contactAction()
	{
		$objContent = new Models_Content();
		/**
		 * Display tempalte
		 */
			
		$content = $objContent->getContentById(29)->toArray();
			
		$this->view->content = $content;
		$this->view->headTitle($content['title']);
		$this->view->menuId = array('join', '');
	}
}